<template>
  <div class="page-container">
    <div class="detail">
      <el-card>
        <div class="list">
          <div class="item set">订单信息</div>
          <div class="item">
            <span>订单编号</span>
            <span class="line">{{ order.orderSnId }}</span>
          </div>

          <div class="item">
            <span>下单时间</span>
            <span class="line">{{ order.createTime }}</span>
          </div>

          <div class="item">
            <span>文件数量</span>
            <span class="line underline cursor">{{ initFiles.length }}</span>
            <el-button style="margin-left: 10px;" v-hasPermi="['order:file:manager']" icon="el-icon-edit" size="mini"
              @click="openNormalFileWindow(initFiles)">管理文件</el-button>
          </div>

          <div class="item">
            <span>用户id</span>
            <span class="line">{{ order.userId }}</span>
          </div>

          <div class="item">
            <span>姓名</span>
            <span class="line">{{ order.userName }}</span>
          </div>

          <div class="item">
            <span>服务类型</span>
            <span>{{ order.serviceName || listServiceManager[order.serviceId] }}</span>
            <el-tag class="line">{{
              serviceStatus[order.serviceStatus]
            }}</el-tag>
          </div>

          <div class="item" v-if="[1, 2, 3, 4, 5, 6, 7, 8].includes(order.serviceId)">
            <span>专业领域</span>
            <span class="line">{{ order.professionalField }}</span>
          </div>

          <div class="item" v-if="[1, 2, 3, 4, 5, 6, 7, 8].includes(order.serviceId)">
            <span>文章标题</span>
            <span class="line">
              {{ order.article || '无' }}
              <el-button style="margin-left: 10px;" v-if="[2, 3].includes(order.orderStatus)" size="mini"
                @click="editOrderColumn('article')">
                <i class="el-icon-edit">修改标题</i></el-button>
            </span>
          </div>

          <div class="item" v-if="[1, 2, 3, 4, 6, 7, 8].includes(order.serviceId)">
            <span>{{ showLabel[0] }} </span>
            <span class="line">
              {{ order.wordSize }}
              <el-button v-if="[2, 3].includes(order.orderStatus)" size="mini" @click="editOrderColumn('wordSize')">
                <i class="el-icon-edit">修改字数</i></el-button>
            </span>
          </div>

          <div class="item" v-if="[5].includes(order.serviceId)">
            <span>{{ showLabel[1] }} </span>
            <span class="line">
              {{ order.recommendNumber }}
              <el-button v-if="[2, 3].includes(order.orderStatus)" size="mini"
                @click="editOrderColumn('recommendNumber')">
                <i class="el-icon-edit">修改篇数</i></el-button>
            </span>
          </div>



          <div class="item" v-if="[1, 2, 3, 4, 8, 9, 10].includes(order.serviceId)">
            <span>目标期刊</span>
            <span class="line">{{ order.targetJournal || '无' }}</span>
          </div>

          <div class="item" v-if="[8].includes(order.serviceId)">
            <span>格式</span>
            <span class="line">{{ fileType[order.format] }}</span>
          </div>


          <div class="item">
            <span>订单状态</span>
            <el-tag class="line">
              {{ orderStatus[order.orderStatus] }}
            </el-tag>

          </div>

          <div class="item set">
            <span v-if="[1, 2, 3, 4, 5, 6, 7, 8].includes(order.serviceId)">备注</span>
            <span v-if="[9].includes(order.serviceId)">分析作图要求</span>
            <span v-if="[10].includes(order.serviceId)">绘图要求</span>

            <span class="line">{{ order.remarks || '无' }}</span>
          </div>
        </div>
      </el-card>

      <el-card v-if="[4, 5, 6, 7, 8, 9, 10, 11].includes(order.orderStatus)">
        <div class="list">
          <div class="item set">订单文件信息</div>
          <div class="item">
            <span>报账合同:</span>
            <el-button :disabled="![6, 10, 11].includes(order.orderStatus)" type="primary" size="mini"
              @click="uploadFileShow = true">{{ order.contractFile ? '重新上传' : '上传' }}</el-button>
            <el-button size="mini"" v-if="order.contractFile"
              @click="downloadOrderFile(order.contractFile)">下载</el-button>
          </div>

          <div class="item" v-if="[1, 2, 3, 4].includes(order.serviceId)">
            <span class="translate-span">翻译润色证明:</span>
            <el-button :disabled="![6, 10, 11].includes(order.orderStatus)" type="primary" size="mini"
              @click="uploadFileShow1 = true">{{ order.translationProofFile ? '重新上传' : '上传' }}</el-button>
            <el-button size="mini" v-if="order.translationProofFile"
              @click="downloadOrderFile(order.translationProofFile)">下载</el-button>
          </div>
        </div>
      </el-card>

      <div class="card-groups">
        <el-card class="hight">
          <div class="item set">收费清单</div>
          <div class="list_money">

            <div class="item top">
              <span>{{ listServiceManager[order.serviceId] }}:</span>
              <span class="line line_money">￥{{ order.servicePrice }}</span>
            </div>

            <!-- <div class="item top" v-if="order.urgent">
              <span>加急费用:</span>
              <span class="line line_money">￥{{ order.urgentMoney }}</span>
            </div> -->

            <div class="item top" v-if="order.couponDeductible && order.couponDeductible != 0">
              <span>查重券:</span>
              <span class="line line_money"> - ￥{{ order.couponDeductible}}</span>
            </div>

            <div class="item top">
              <span>总计费用:</span>
              <span class="line line_money">￥{{ order.totalPrice }}</span>
            </div>

            <div class="item top" v-if="order.discount && order.discount !== 100">
              <span>{{order.teamId && order.teamId !== 0 ? '团队折扣' : '个人折扣'}}:</span>
              <span class="line line_money red"> - ￥{{ discountMoney }}</span>
            </div>

            <!-- 默认设置为10， 表示没有支付 -->
            <div class="item top" v-if="order.payType && order.payType !== 10">
              <span>支付方式:</span>
              <span class="line line_money" v-if="1 == order.useCheckConpon">查重券</span>
              <span class="line line_money" v-else>{{ payType[order.payType] }}</span>
            </div>
            <div class="item top" v-if="[1, 2].includes(order.orderStatus)">
              <span>当前需支付金额:</span>
              <span class="line line_money red">￥{{ order.actualPaidPrice
                }}</span>
            </div>
            <div class="item top" v-if="![0, 1, 2].includes(order.orderStatus)">
              <span>实付金额:</span>
              <span class="line line_money red">￥{{ order.orderStatus == -1 ? '0' : order.actualPaidPrice
                }}</span>
            </div>
          </div>
          <!-- <div v-else>
            <el-empty description="暂无报价信息"></el-empty>
          </div> -->
        </el-card>
        <el-card class="hight" v-if="![-1, 0, 1, 2, 3].includes(order.orderStatus)">
          <div class="item set">编辑信息</div>
          <div class="edit-list-wrap" v-if="![-1, 0, 1, 2, 3, 5].includes(order.orderStatus)">
            <div class="edit-list" v-for="item,index in processorsList" :key="index">
              <div class="list-item">
              <div class="item-label">处理人</div>
              <div class="item-value">{{ item.processName }} (ID:{{ item.processed }})</div>
            </div>
            <div class="list-item">
              <div class="item-label">派稿时间</div>
              <div class="item-value">{{ timestampToDate(item.dispatchTime) }}</div>
            </div>
            <div class="list-item">
              <div class="item-label">返稿时间</div>
              <div class="item-value">{{
              formatDate(item.returnTime * 1000)
            }}</div>
            </div>
            <div class="list-item">
              <div class="item-label">编辑金额</div>
              <div class="item-value">¥ {{ item.processMoney }} <el-button size="mini"
                  @click="editOrderColumn('processMoney', item)">
                  <i class="el-icon-edit">修改金额</i></el-button>
              </div>
            </div> 
            </div>
          </div>
          <div v-else>
            <el-empty description="暂无编辑信息"></el-empty>
          </div>
        </el-card>
      </div>

      <el-card v-if="order.commentStatus === 1">
        <div class="card-header">
          <div class="item set">服务评价</div>
          <div class="service-evaluation-time">{{ timestampToDate(order.overTime) }}</div>
        </div>
        <div class="card-content">
          <div class="card-content-label">服务评分</div>
          <div class="card-content-value">
            <el-rate v-model="order.score" disabled></el-rate>
          </div>
        </div>

        <div class="card-content">
          <div class="card-content-label">评价内容</div>
          <div class="card-content-value">
            {{ order.comment }}
          </div>
        </div>


      </el-card>

      <el-card v-if="order.orderStatus === 8 && isAudit">
        <div class="item set">订单审核</div>
        <el-form ref="auditForm" :model="auditParams" :rules="auditRules" label-position="left">
          <el-form-item label="服务类型" prop="serviceType">
            <el-radio-group v-model="auditParams.serviceType">
              <el-radio :label="1">反馈服务</el-radio>
              <el-radio :label="2">售后服务</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="审核结果" prop="status">
            <el-radio-group v-model="auditParams.status">
              <el-radio :label="0">通过</el-radio>
              <el-radio :label="1">不通过</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="处理人" v-if="auditParams.status === 0" prop="processName">
            <div style="display: flex; align-items: center;">
              <el-button type="primary" size="mini" @click="dispatcherVisible = true; isSubmit= false">选择编辑</el-button> <div style="margin-left: 10px;">{{ auditParams.processName }}</div>
            </div>
          </el-form-item>


          <el-form-item label="审核原因" prop="requirement" v-if="auditParams.status === 1">
            <el-input style="width: 400px;" v-model="auditParams.requirement" placeholder="请输入审核原因"></el-input>
          </el-form-item>
          <el-form-item label="上传附件" v-if="auditParams.status === 1" prop="files">
            <el-button @click="uploadFileShow2 = true">上传附件</el-button> <span style="margin-left: 10px; color:gray;">{{
              auditParams.files.length ?
                auditParams.files[0].originName : '' }}</span>
          </el-form-item>
        </el-form>


      </el-card>

    </div>
    <el-card class="el-card-time">
      <div class="item top" style="margin-bottom: 20px">
        <span>时间轴:</span>
      </div>
      <el-timeline class="time_h">
        <el-timeline-item v-for="(item, index) in listLog" :key="index" placement="bottom"
          :timestamp="timestampToDate(item.createTime)" :color="logColor[index]">
          <div v-if="item.orderStatus == 10 || 11 == item.orderStatus">
            申请二次服务
            <div class="log_color">
              <p>服务类型： {{ logStatus[item.orderStatus] }}</p>
              <p>
                文件数量：<span @click="lookFiles(item.manuscript)" class="underline cursor">{{ item.manuscript ?
              item.manuscript.length : 0
                  }}</span>
              </p>
              <p style="word-break: break-all; line-height: 1.5;">需求描述：{{ item.requirement }}</p>
            </div>
          </div>
          <div v-else-if="7 == item.orderStatus">
            {{ logStatus[item.orderStatus] }}
            <p style="word-break: break-all; line-height: 1.5;">审核原因: {{ item.requirement }}</p>
            <p v-if="item.manuscript">
              上传附件：<span @click="lookFiles(item.manuscript)" class="underline cursor">{{ item.manuscript ?
              item.manuscript.length : 0
                }}</span>
            </p>
          </div>
          <div v-else-if="9 == item.orderStatus && item.requirement">
            {{ logStatus[item.orderStatus] }}
            <p style="word-break: break-all; line-height: 1.5;">关联订单: {{ item.requirement }}</p>
          </div>
          <div v-else-if="18 == item.orderStatus">
            {{ logStatus[item.orderStatus] }}
            <p style="word-break: break-all; line-height: 1.5;">驳回原因: {{ item.requirement }}</p>
          </div>
          <div v-else-if="1 == item.orderStatus">
            {{ logStatus[item.orderStatus] }} : {{ item.price }}
          </div>
          <div v-else>
            {{ logStatus[item.orderStatus] }}
          </div>
        </el-timeline-item>
      </el-timeline>
    </el-card>
    <el-card class="footer-card">
      <!-- 关闭 -->
      <el-button @click="cancel" v-if="order.orderStatus !== 8 || !isAudit">关闭</el-button>
      <!-- 下载稿件 -->
      <el-button type="primary" v-hasPermi="['userManager:user:edit']" @click="downloadFile(initFiles)"
        v-if="[0, 1].includes(order.orderStatus)">下载稿件</el-button>
      <!-- 报价 -->
      <el-button type="primary" v-hasPermi="['userManager:user:edit']" @click="editOrderColumn('servicePrice')"
        v-if="[0, 1].includes(order.orderStatus)"> {{ order.orderStatus === 0 ? '报价' : '修改报价' }}</el-button>
      <!-- 取消订单 -->
      <el-button v-hasPermi="['userManager:user:edit']" v-if="[2, 3].includes(order.orderStatus)"
        @click="orderCancel">取消订单</el-button>
      <!-- 派稿 -->
      <el-button type="primary" v-hasPermi="['userManager:user:edit']" v-if="[5].includes(order.orderStatus)"
        @click="dispatcherVisible = true; isSubmit= true">派稿</el-button>
      <!-- 驳回 -->
      <el-button v-hasPermi="['userManager:user:edit']" v-if="[6].includes(order.orderStatus)"
        @click="handleOrderReject">驳回</el-button>
      <!-- 完工确认 -->
      <el-button type="primary" v-hasPermi="['userManager:user:edit']" v-if="[6].includes(order.orderStatus)"
        @click="handleOrderConfirm">完工确认</el-button>
      <!-- 成稿下载 -->
      <el-button type="primary" v-hasPermi="['userManager:user:edit']" v-if="[6, 10, 11].includes(order.orderStatus)"
        @click="downloadFileLast(editFiles)">成稿下载</el-button>
      <!-- 审核 -->
      <el-button type="primary" v-hasPermi="['userManager:user:edit']"
        v-if="[8].includes(order.orderStatus) && !isAudit" @click="addAudit">审核</el-button>



      <el-button type="primary" v-hasPermi="['userManager:user:edit']" v-if="[8].includes(order.orderStatus) && isAudit"
        @click="handleAuditCancel">取消</el-button>
      <el-button type="primary" v-hasPermi="['userManager:user:edit']" v-if="[8].includes(order.orderStatus) && isAudit"
        @click="handleAuditConfirm" :loading="auditLoading">提交</el-button>

    </el-card>
    <div style="width: 100%; height: 80px;"></div>
    <!-- 创建 close-->
    <manscript-box :visible="visibleFile" :order="order" :manuscript="manuscript" @closeDialog="closeFileDialog"
      @confirm="confirm"></manscript-box>
    <commonEdit :visible="visible" :secondLabel="editLabel[currentKey]" :placeholder="editLabel[currentKey]"
      :qutationData="orderCopy" :URL="editUrl[currentKey]" :editKey="editKey[currentKey]" @close="closeDialog"
      @receiveData="receiveData" :iptType="editType[currentKey]">
      <template v-if="currentKey === 'processMoney'">
        <el-form-item label="处理人" label-width="100px" required>
          <el-input :value="orderCopy.processName + ' ( ID:' + orderCopy.processed + ' )'" :placeholder="placeholder"
            disabled></el-input>
        </el-form-item>
      </template>

    </commonEdit>

    <dispatcher v-if="dispatcherVisible" @close="closeDispatcherDialog" @receiveData="receiveAssignData" :order="order"
      :visible="dispatcherVisible" :isSubmit="isSubmit" :Obj="processItem"></dispatcher>

    <el-dialog :visible.sync="uploadFileShow" title="上传报账合同">
      <oss :limit="1" :value="order.contractFile" :isShowTip="false" :fileType="[]" uploadType="text"
        @input="e => contractFile = e" @deleteContract="deleteContract" deleteCallbackName="deleteContract"
        ossURL="/oss/uploadContract">
      </oss>
      <span slot="footer" class="dialog-footer">
        <el-button @click="uploadFileShow = false">取 消</el-button>
        <el-button type="primary" @click="saveContract">上传</el-button>
      </span>
    </el-dialog>
    <el-dialog :visible.sync="uploadFileShow1" title="上传翻译润色证明">
      <oss :limit="1" :value="order.translationProofFile" :isShowTip="false" :fileType="[]"
        @input="e => translationProofFile = e" ossURL="/oss/uploadTranslateFile"
        deleteCallbackName="deleteTranslationProof" uploadType="text" @deleteTranslationProof="deleteTranslationProof">
      </oss>
      <span slot="footer" class="dialog-footer">
        <el-button @click="uploadFileShow1 = false">取 消</el-button>
        <el-button type="primary" @click="saveTranslationProof">上传</el-button>
      </span>
    </el-dialog>

    <el-dialog title="驳回编辑" :visible.sync="rejectFormVisible" destroy-on-close>
      <el-form ref="rejectForm" :model="rejectForm" :rules="rejectFormRules" label-position="left" label-width="80px">
        <el-form-item label="订单编号" prop="orderSnId">
          <el-input v-model="rejectForm.orderSnId" disabled></el-input>
        </el-form-item>
        <el-form-item label="驳回原因" prop="reason">
          <el-input placeholder="请输入驳回原因" v-model="rejectForm.reason" type="textarea" :rows="2"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="rejectFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitOrderReject">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="uploadFileShow2" title="上传附件">
      <oss :limit="1" :value="auditFiles" :showTip="false" @input="e => auditFiles = e"
        @fileListChange="e => auditParams.files = e" uploadType="text" ossURL="/oss/uploadManuscripts"
        deleteCallbackName="deleteAuditFile" @deleteAuditFile="e => auditFiles = e" :fileType="[]"></oss>
      <span slot="footer" class="dialog-footer">
        <el-button @click="uploadFileShow2 = false">取 消</el-button>
        <el-button type="primary" @click="uploadFileShow2 = false">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { logByOrderId } from '@/api/order/log';
import {
  EDIT_BY_ORDER_KEY,
  EDIT_DESCRIPTION,
  EDIT_ORDER_URL,
  ORDERS_MOUDLE_TATUSES,
  ORDER_DETAIL_SHOW_LABEL,
  ORDER_LOG_STATUS,
  SERVICE_STATUS,
  FIELD_TYPE
} from '@/constant/const'
import { timestampToDate, formatDate } from '@/utils/time'
import { listByOrderId } from '@/api/order/manuscript'
import { listPayType, listPayTypeJSON } from '@/api/configManager/payType'
import { updateContractOrder, updateOrder, assignOrder, getOrderHandlerList, updateTranslationProofOrder, editPersonnel, getOrder, cancelOrder, rejectOrder, confirmOrder, auditOrder } from '@/api/order/order'
import { formatSize, classifyFile } from '@/utils/file'
import { download } from '@/utils/request'
import { downloadFile, downloadZip } from '@/utils/dowload';
import { Message } from 'element-ui';
import { accAdd, accMul } from "@/utils/math"
export default {
  components: {
    manscriptBox: () => import('./component/manscript.vue'),
    oss: () => import('@/components/ImageUpload/oss.vue'),
    commonEdit: () => import('./component/commomEditValue.vue'),
    dispatcher: () => import('./component/dispatcher.vue'),
  },
  data() {
    return {
      isSubmit:true,
      order: {},
      orderCopy: {},
      orderStatus: ORDERS_MOUDLE_TATUSES,
      logStatus: ORDER_LOG_STATUS,
      showLabel: ORDER_DETAIL_SHOW_LABEL,
      serviceStatus: SERVICE_STATUS,
      editLabel: EDIT_DESCRIPTION,
      editKey: EDIT_BY_ORDER_KEY,
      editType: FIELD_TYPE,
      editUrl: EDIT_ORDER_URL,
      currentKey: undefined,
      // 返稿文件格式
      fileType: ["Latex", "Word"],
      editColumn: undefined,
      placeholder: undefined,
      secondLabel: undefined,
      visible: false,
      visibleFile: false,
      normalManuscript: [], // 正常的
      manuscript: [],
      listServiceManager: {},
      logColor: {
        0: '#1990FF'
      },
      payType: {},

      listLog: [],
      orderId: null,
      isAudit: false,
      uploadFileShow: false,
      uploadFileShow1: false,
      overLoading:false,
      contractFile: null,
      translationProofFile: null,
      uploadFileShow2: false,
      auditParams: {
        id: '',
        payManagerId: '',
        requirement: '',
        status: 0,
        userId: '',
        files: [],
        processName: null
      },
      auditLoading:false,
      auditFiles: "",
      auditRules: {
        serviceType: [
          { required: true, message: '请选择服务类型', trigger: 'change' }
        ],
        status: [
          { required: true, message: '请选择审核状态', trigger: 'change' }
        ],
        processName: [
          { required: true, message: '请选择处理人', trigger: 'change' }
        ],
        requirement: [{ required: true, message: '请输入审核原因', trigger: 'blur' }],
        files: [{ required: true, message: '请上传附件', trigger: 'change' }]
      },
      rejectFormRules: {
        reason: [
          { required: true, message: '请输入驳回原因', trigger: 'blur' }
        ]
      },
      //用户提交初始文件
      initFiles: [],
      //编辑返稿文件
      editFiles: [],
      //用户提交的二次服务文件
      secondFiles: [],
      dispatcherVisible: false, //派稿弹窗
      rejectFormVisible: false, //驳回
      rejectForm: {
        id: '',
        reason: '',
        orderSnId: ''
      },
      // 当前处理人列表
      processorsList:[],
      processItem:{}
    }
  },

  created() {
    this.$nextTick(() => {
      this.orderId = this.$route.params.id;
      this.order = JSON.parse(sessionStorage.getItem('orderItem'))

      this.order.orderSn = this.order.orderSnId;
      this.order.serviceName = this.order.serviceTypeName;
      let listServiceManager = JSON.parse(sessionStorage.getItem('managerList'))

      let json = {}

      listServiceManager.forEach((element) => {
        json[element.id] = element.typeName
      })
      this.listServiceManager = json;
      let param = { id: this.orderId }
      this.getOrderLogs();
      listPayTypeJSON(this);
      this.getDetail(param.id);
      this.getAllFiles();
      this.auditParams = {
        ...this.auditParams,
        id: this.orderId,
        userId: this.order.userId,
        payManagerId: this.order.payManagerId,
        serviceType: this.order.serviceStatus
      }
      let auditObj = JSON.parse(sessionStorage.getItem('isAudit'));
      if (auditObj && auditObj.id == this.orderId) {
        this.isAudit = auditObj.isAudit;
      }
      if(this.order.orderStatus !==8){
        this.handleAuditCancel()
      }
    })
  },

  mounted() {

  },

  methods: {
    timestampToDate,
    // 获取文件
    async getAllFiles() {
      return await listByOrderId({ id: this.orderId }, this).then(res => {
        this.initFiles = res.filter(item => {
          return !item.editorUserId
        });
        let editFiles = classifyFile(res).editorReturned;
        let editFilesLast = editFiles.length ? editFiles[editFiles.length - 1].files : [];
        this.editFiles = editFilesLast;
      })
    },
    formatDate,
    // 获取订单日志
    getOrderLogs() {
      logByOrderId({ id: this.orderId }, this);
      this.getProcessors()
    },




    //完工确认
    handleOrderConfirm(item) {
      this.$confirm('确定编辑已完成订单处理吗?', '完工提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        confirmOrder(this.orderId).then(res => {
          Message.success('操作成功');
          this.getDetail(this.orderId);
          this.getOrderLogs()
        })
      })

    },
    //驳回
    handleOrderReject() {
      this.rejectForm.id = this.orderId;
      this.rejectForm.orderSnId = this.order.orderSnId;
      this.rejectFormVisible = true
    },

    submitOrderReject() {
      this.$refs['rejectForm'].validate().then(result => {
        if (!result) return;
        rejectOrder(this.rejectForm).then(res => {
          Message.success('驳回成功');
          this.rejectFormVisible = false;
          this.getDetail(this.orderId);
          this.getOrderLogs()
        })
      })
    },

    // 下载单个文件证明
    downloadOrderFile(file, fileName) {
      let name = fileName || this.getFileNameFromUrl(file);
      downloadFile(file, name);
    },

    // 截取文件名
    getFileNameFromUrl(url) {
      // 从链接中获取最后一个斜杠后的内容作为文件名
      const index = url.lastIndexOf('/');
      return url.substring(index + 1);
    },

    // 获取当前订单处理人列表
    getProcessors(){
      getOrderHandlerList({
        orderId: this.order.id,
        processed: 0,
        userId: this.order.userId
      }).then(res=>{
        this.processorsList = res.data
      })
    },


    receiveAssignData(data) {
      if(!this.isSubmit){
        this.processItem = data;
        this.auditParams.processName = this.processItem.processName
        return;
      }
      this.order.orderStatus = 4;
      this.getDetail(this.orderId);
      this.getOrderLogs();
    },
    closeDispatcherDialog(value) {
      this.dispatcherVisible = value
    },
    // 取消订单
    orderCancel() {
      this.$confirm('确定要取消该订单吗?', '系统提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        cancelOrder(this.order.id).then(res => {
          Message.success('取消成功')
          this.getDetail(this.orderId);
          this.getOrderLogs()
        })
      })
    },

    // 获取编辑人员信息
    getEditUser() {
      editPersonnel(order.processd).then(res => {
        console.log(res);
      })
    },

    //进入审核状态
    addAudit() {
      this.auditParams = {
        ...this.auditParams,
        id: this.orderId,
        userId: this.order.userId,
        payManagerId: this.order.payManagerId,
        serviceType: this.order.serviceStatus
      }
      this.isAudit = true;
      sessionStorage.setItem('isAudit', JSON.stringify({
        id: this.orderId,
        isAudit: true
      }))
    },
    // 取消审核状态
    handleAuditCancel() {
      this.isAudit = false;
      sessionStorage.setItem('isAudit', JSON.stringify({
        id: this.orderId,
        isAudit: false
      }));
    },

    //审核提交
    handleAuditConfirm() {
      this.$refs.auditForm.validate( async (valid) => {
        if (!valid) return;
        this.auditLoading = true;
        let params = this.auditParams.status === 0? {...this.auditParams,...this.processItem, ...{ returnTime: this.processItem.returnTime / 1000} } : this.auditParams;
        try {
          let res = await auditOrder(params);
        this.handleAuditCancel();
        sessionStorage.removeItem('isAudit');
        Message.success('操作成功');
        this.getDetail(this.orderId);
        this.getOrderLogs();
        this.auditLoading = false;
        } catch (error) {
          
        } finally {
          this.auditLoading = false;
        }
      })

    },

    // 订单详情信息
    getDetail(id) {
      return new Promise((resolve, reject) => {
        getOrder(id).then(res => {
          let newObj = this.removeNullFields(res.data)
          this.order = Object.assign({}, this.order, newObj);
          this.order.createTime = timestampToDate(this.order.createTime);
          resolve(res);
        }).catch(err => {
          reject(err);
        })
      })

    },

    async confirm() {
      await this.getAllFiles();
      console.log("结束");
      this.openNormalFileWindow(this.initFiles);
    },

    removeNullFields(obj) {
      for (let key in obj) {
        if (obj[key] === null) {
          delete obj[key];
        }
      }

      return obj
    },

    /**
     * 
     * @param {Array} files 
     */
    saveContract() {
      if (!this.contractFile) {
        Message.error('请先上传合同文件');
        return;
      }
      updateContractOrder({
        id: this.order.id,
        contractFile: this.contractFile
      }).then(res => {
        this.$message.success(res.msg);
        this.order.contractFile = this.contractFile;
        this.uploadFileShow = false;
        sessionStorage.setItem("orderItem", JSON.stringify(this.order));
      });

    },
    /**
     * 翻译证明
     * @param {Array} files 
     */
    saveTranslationProof() {
      if (!this.translationProofFile) {
        Message.error('请先上传翻译证明文件');
        return;
      }
      updateTranslationProofOrder({
        id: this.order.id,
        translationProofFile: this.translationProofFile
      }).then(res => {
        this.$message.success(res.msg);
        this.uploadFileShow1 = false;
        this.order.translationProofFile = this.translationProofFile;
        sessionStorage.setItem("orderItem", JSON.stringify(this.order));
      });
    },

    deleteTranslationProof(file) {
      this.order.translationProofFile = undefined;
      sessionStorage.setItem("orderItem", JSON.stringify(this.order));
    },

    deleteContract(file) {
      this.order.contractFile = undefined;
      sessionStorage.setItem("orderItem", JSON.stringify(this.order));
    },


    async receiveData(data, key, res) {
      this.order[key] = data[key];
      let detail = await this.getDetail(this.order.id);
      sessionStorage.setItem('orderItem', JSON.stringify(this.order));
      this.getOrderLogs()
      this.$forceUpdate();
    },

    /**
     * 修改订单column
     */
    editOrderColumn(column, item) {
      this.currentKey = column;
      this.editColumn = this.editKey[column];
      this.placeholder = this.editLabel[column];
      this.secondLabel = this.editLabel[column];
      //处理人补丁(zheng he de nan gai de yao ming)
      if(column === 'processMoney'){
        this.orderCopy = Object.assign({}, this.order, item);
        console.log(this.orderCopy);
      }else{
        this.orderCopy = Object.assign({},this.order)
      }
      this.visible = true
    },

    /**
     * 打开正常的文件列表
     * @param {[]} manscripts
     */
    openNormalFileWindow(manscripts) {
      this.manuscript = manscripts
      this.visibleFile = true
    },
    closeDialog(visible) {
      this.visible = visible
    },
    closeFileDialog(visible) {
      this.visibleFile = visible
    },

    submitForm() {

    },

    /**
     * 下载稿件
     */
    downloadFile(file) {
      file.forEach(item => {
        downloadFile(item.file, item.originName)
      })
    },

    /**成稿下载 */
    downloadFileLast(file) {
      console.log("file", file);
      downloadZip(file, this.order.serviceTypeName + this.order.orderSnId)
      // file.forEach(item => {
      //   downloadFile(item.file, item.originName)
      // })
    },

    cancel() {
      this.$router.back()
    },

    /**
     *
     * @param {Array<{}>} manuscript
     */
    lookFiles(manuscript) {
      this.manuscript = manuscript
      this.visibleFile = true
    }
  },

  computed: {
    discountMoney() {
      let num = 0;
      let totalPrice = this.order.totalPrice || 0;
      let discount = accMul(this.order.discount, 0.01) || 1; //折扣
      let discountM = accAdd(1, - discount) || 0; //减免率
      num = accMul(totalPrice, discountM);
      return num;
    },

  },

  watch: {

  },

  filters: {}
}
</script>

<style scoped>
.page-container {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  height: calc(100vh - 50px);
  overflow: auto;
  padding: 20px;
  padding-top: 0;
  padding-bottom: 0;
}

.list {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-gap: 10px;
  grid-auto-rows: max-content;
  background-color: #fff;
}

.time_h {
  margin-left: -40px;
  margin-top: 8px;
}

.list_money {
  width: 600px;
  max-width: 100%;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  background-color: #fff;
  padding-right: 30px;

}

.list_money .item {
  width: 100%;
  display: flex;
  margin-left: 0;
  justify-content: space-between;
}

.red {
  color: red;
}

.top {
  margin-top: 10px;
}

.time_axis {
  width: 15%;
  display: flex;
  flex-direction: column;
  background-color: #fff;
}

.log_color {
  background-color: #f7f9fd;
  padding: 5px 20px;
  margin-top: 10px;
  border-radius: 10px;
}

.detail {
  width: 83%;
}

.footer-card {
  text-align: center;
  width: 100% !important;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: fit-content;
  padding: 0;
  height: 70px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.footer-card /deep/ .el-card__body {
  padding: 0;
}

.item {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  margin-top: 12px;


}

.item span:nth-child(1) {
  display: inline-block;
  width: 140px;
  margin-right: 40px;
}

.component-upload-image>>>.el-upload-dragger {
  width: 100% !important;
  height: 100% !important;
}

.translate-span {
  width: 105px !important;
}

.set {
  /* 占满整行 */
  grid-column: 1 / 4;
}

.line {
  margin-left: 20px;
}

.line_money {
  display: inline-block
}

.hight {
  min-height: 250px;
  flex: 1;
}

.card-groups {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-right: 20px;
}

.underline {
  text-decoration: underline;
  color: #409eff;
  font-size: 14px;
  text-decoration-color: #409eff;
  margin-left: 11px;
}

.cursor {
  cursor: pointer;
}

.el-card {
  width: 98%;
  margin-top: 1%;
}

.el-card-time {
  width: 17%;
  height: calc(100vh - 150px);
  position: sticky;
  top: 15px;
  overflow: auto;
  border-radius: 10px;
}

.edit-list-wrap{
   margin-top: 20px;
   max-height: 220px;
   overflow-y: auto;
}
.edit-list {
  width: 100%;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 20px;
}

.edit-list + .edit-list{
  padding-top: 15px;
  margin-top: 15px;
  border-top: 1px solid #000;
}


.list-item {
  width: calc(50% - 20px);

}

.list-item {
  display: flex;
  align-items: center;
}

.item-label {
  width: 40%;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.service-evaluation-time {
  margin-top: 12px;
}

.card-content {
  width: 100%;
  margin-top: 10px;
  display: flex;
  align-items: flex-start;
}

.card-content+.card-content {
  margin-top: 20px;
}

.card-content-label {
  width: 120px;
}

.card-content-value {
  flex: 1;
  word-wrap: break-word;
  word-break: break-all;
}
</style>
